﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam2.Biz;
using MockPrjTeam2.Entity;
namespace MockPrjTeam2.Pages.Forms
{
    public partial class AddSupportingMaterial : System.Web.UI.Page
    {
        private int OrgId;
        private SupportingMeterialBiz supportingMeterialBiz;
       // private OrganizationBuz organizationBuz;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request.Params["organisationId"], out OrgId))
            {
                Response.Redirect("../Views/ListOrganizations.aspx");
            }
            else
            {
                supportingMeterialBiz = new SupportingMeterialBiz();
            }

            if (!IsPostBack)
            {
               
                BindFields();
            }
        }
        private void BindFields()
        {
                    HiddenFieldUserId.Value =Convert.ToString(Session["userId"]);
                    TextBoxAddedBy.Text = Session["username"].ToString();
                    // HiddenFieldUserId.Value = Convert.ToInt32(suppportingMaterial.UserID).ToString(CultureInfo.InvariantCulture);
                    TextBoxAddedDate.Text = DateTime.Now.ToShortDateString();
                
           }
        public void Success(string text)
        {

            LiteralSuccess.Text = text;

        }
        protected void ButtonSaveClick(object sender, EventArgs e)
        {
            SupportingMeterial supportingMeterial=new SupportingMeterial();
            //SupportingMeterialBiz supportingMeterialBiz=new SupportingMeterialBiz();
            supportingMeterial.UserID =Convert.ToInt32(HiddenFieldUserId.Value.ToString(CultureInfo.InvariantCulture));
            supportingMeterial.OrgId = OrgId;
            supportingMeterial.Url = TextBoxURL.Text;
            supportingMeterial.Description = TextBoxDescription.Text;
            supportingMeterial.Type = DropDownListType.SelectedItem.Value.ToString(CultureInfo.InvariantCulture);
            supportingMeterial.AddDate =Convert.ToDateTime(TextBoxAddedDate.Text);
           bool result= supportingMeterialBiz.AddSupportingMaterial(supportingMeterial);
            if(result)
            {
                PanelSuccess.Visible = true;
                Success("successfully");
                TextBoxURL.Text = string.Empty;
                TextBoxDescription.Text = string.Empty;
            }
            else
            {
                lblSuccess.Text = string.Empty;
            }
          
        }

        protected void ButtonBack_Click(object sender, EventArgs e)
        {
            if (int.TryParse(Request.Params["organisationId"], out OrgId))
            {
                Response.Redirect(string.Format(CultureInfo.CurrentCulture,
                                                "OrganizationDetails.aspx?id={0}#DetailsPanel05", OrgId));
            }
        }

      
    }
}